package com.ruoyi.project.lesson.channel.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.lesson.channel.domain.LessonChannel;
import com.ruoyi.project.lesson.channel.service.ILessonChannelService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 课程渠道Controller
 * 
 * @author shixiangwen
 * @date 2021-04-21
 */
@Controller
@RequestMapping("/lesson/channel")
public class LessonChannelController extends BaseController
{
    private String prefix = "lesson/channel";

    @Autowired
    private ILessonChannelService lessonChannelService;

    @RequiresPermissions("lesson:channel:view")
    @GetMapping()
    public String channel()
    {
        return prefix + "/channel";
    }

    /**
     * 查询课程渠道列表
     */
    @RequiresPermissions("lesson:channel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LessonChannel lessonChannel)
    {
        startPage();
        List<LessonChannel> list = lessonChannelService.selectLessonChannelList(lessonChannel);
        return getDataTable(list);
    }

    /**
     * 导出课程渠道列表
     */
    @RequiresPermissions("lesson:channel:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LessonChannel lessonChannel)
    {
        List<LessonChannel> list = lessonChannelService.selectLessonChannelList(lessonChannel);
        ExcelUtil<LessonChannel> util = new ExcelUtil<LessonChannel>(LessonChannel.class);
        return util.exportExcel(list, "channel");
    }

    /**
     * 新增课程渠道
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程渠道
     */
    @RequiresPermissions("lesson:channel:add")
    @Log(title = "课程渠道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LessonChannel lessonChannel)
    {
        return toAjax(lessonChannelService.insertLessonChannel(lessonChannel));
    }

    /**
     * 修改课程渠道
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LessonChannel lessonChannel = lessonChannelService.selectLessonChannelById(id);
        mmap.put("lessonChannel", lessonChannel);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程渠道
     */
    @RequiresPermissions("lesson:channel:edit")
    @Log(title = "课程渠道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LessonChannel lessonChannel)
    {
        return toAjax(lessonChannelService.updateLessonChannel(lessonChannel));
    }

    /**
     * 删除课程渠道
     */
    @RequiresPermissions("lesson:channel:remove")
    @Log(title = "课程渠道", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lessonChannelService.deleteLessonChannelByIds(ids));
    }
}
